package com.ruoyi.web.controller.swimming;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swimming.domian.CourseCoach;
import com.ruoyi.swimming.service.ICourseCoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教练Controller
 * 
 * @author ruoyi
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/system/coach")
public class CourseCoachController extends BaseController
{
    @Autowired
    private ICourseCoachService courseCoachService;

    /**
     * 查询教练列表
     */
    @PreAuthorize("@ss.hasPermi('system:coach:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseCoach courseCoach)
    {
        startPage();
        List<CourseCoach> list = courseCoachService.selectCourseCoachList(courseCoach);
        return getDataTable(list);
    }

    /**
     * 导出教练列表
     */
    @PreAuthorize("@ss.hasPermi('system:coach:export')")
    @Log(title = "教练", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CourseCoach courseCoach)
    {
        List<CourseCoach> list = courseCoachService.selectCourseCoachList(courseCoach);
        ExcelUtil<CourseCoach> util = new ExcelUtil<CourseCoach>(CourseCoach.class);
        return util.exportExcel(list, "教练数据");
    }

    /**
     * 获取教练详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:coach:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(courseCoachService.selectCourseCoachById(id));
    }

    /**
     * 新增教练
     */
    @PreAuthorize("@ss.hasPermi('system:coach:add')")
    @Log(title = "教练", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseCoach courseCoach)
    {
        return toAjax(courseCoachService.insertCourseCoach(courseCoach));
    }

    /**
     * 修改教练
     */
    @PreAuthorize("@ss.hasPermi('system:coach:edit')")
    @Log(title = "教练", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseCoach courseCoach)
    {
        return toAjax(courseCoachService.updateCourseCoach(courseCoach));
    }

    /**
     * 删除教练
     */
    @PreAuthorize("@ss.hasPermi('system:coach:remove')")
    @Log(title = "教练", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseCoachService.deleteCourseCoachByIds(ids));
    }
}
